package liangtWorkSpace.Observer.version5;

/**
 * @ClassName Cliend
 * @Description : 功能说明
 * @Author : LiangT
 * @Date : 2020/4/16 18:44
 */

import java.util.ArrayList;
import java.util.List;

/**
 * 加入三个观察者-优化一
 */
public class Cliend {
    private boolean cry = false;
    private List<Observer> observers = new ArrayList<>();
    {
        observers.add(new Dad());
        observers.add(new Mam());
        observers.add(new Dog());
    }

    public boolean isCry(){return cry;}

    public void weakUp(){
        System.out.println("crying ....");
        cry = true;
        for (Observer o: observers){
            o.acctionOnWakeUp();
        }
    }

    public void weakUp(Observer o){
        System.out.println("crying ....");
        cry = true;
        o.acctionOnWakeUp();
    }

    public static void main(String[] args) {
        Cliend cliend = new Cliend();
        cliend.weakUp(()->{
            System.out.println("吃饭了！");
        });
    }
}

class Dad implements Observer{
    public void feed(){
        System.out.println("dad feeding.....");
    }

    @Override
    public void acctionOnWakeUp() {
        feed();
    }
}

class Mam implements Observer{
    public void feed(){
        System.out.println("dad feeding.....");
    }

    @Override
    public void acctionOnWakeUp() {
        feed();
    }
}

class Dog implements Observer{
    public void feed(){
        System.out.println("dad feeding.....");
    }
    @Override
    public void acctionOnWakeUp() {
        feed();
    }
}
